package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.org.ClassHasUser;
import top.hcode.hoj.service.admin.AdminClassHasUserService;

/**
 * @author orangej
 * @since 2025-01-21
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AdminClassHasUserController {

    private final AdminClassHasUserService classHasUserService;

    @GetMapping("/admin/class-has-user/list")
    public CommonResult<IPage<ClassHasUser>> getClassHasUserList(QuerySampleDTO querySampleDTO) {
        return CommonResult.successResponse(classHasUserService.getClassHasUserList(querySampleDTO));
    }

    @PostMapping("/admin/class-has-user/save")
    public CommonResult<ClassHasUser> saveClassHasUser(@RequestBody ClassHasUser classHasUser) {
        return CommonResult.successResponse(classHasUserService.saveClassHasUser(classHasUser));
    }

    @PostMapping("/admin/class-has-user/delete")
    public CommonResult<Void> deleteClassHasUser(@RequestBody BaseIdDTO dto) {
        classHasUserService.deleteClassHasUser(dto.getId());
        return CommonResult.successResponse();
    }

}
